package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.Crop;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 作物DAO
 */
@Repository
public class CropDao extends BaseDao<Crop> {
    
    @Override
    protected String getFileName() {
        return "crops.json";
    }
    
    @Override
    protected TypeReference<List<Crop>> getTypeReference() {
        return new TypeReference<List<Crop>>() {};
    }
    
    @Override
    protected Long getId(Crop entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(Crop entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据作物名称查询
     */
    public List<Crop> findByCropName(String cropName) {
        return findAll().stream()
            .filter(crop -> crop.getCropName().contains(cropName))
            .toList();
    }
}

